import { GetCateDetail } from "~/api";

export const useContent = (key) => {
    const route = useRoute();
    const id = route.params.id;
    const type = ref("");
    const detail = ref({}); // 内容详情

    const GetDetail = async () => {
        const res = await GetCateDetail({ id });
        if (res.code == 200) {
            detail.value = res.data;
            if (/\.(png|jpg)/i.test(res.data[key])) {
                type.value = "image";
            } else if (/\.mp4/i.test(res.data[key])) {
                type.value = "video";
            } else {
                if (res.data[key]) {
                    type.value = "iframe";
                } else {
                    throw createError({
                        statusCode: 404,
                    });
                }
            }
        } else {
            Message().error(res.msg);
        }
    };

    return {
        type,
        detail,
        GetDetail,
    };
};
